package com.lxl.bt.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.lxl.bt.R;
import com.lxl.bt.activity.BaseFragment;
import com.lxl.bt.bean.ProductBean;
import com.lxl.bt.databinding.FragmentDetailArgumentsBinding;
import com.lxl.bt.databinding.LayoutItemArgumentsBinding;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by HouJie on 4/10/21
 */
public class DetailArgumentsFragment extends BaseFragment {
    @NonNull
    private FragmentDetailArgumentsBinding bind;

    @Override
    public void getData() {

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_detail_arguments, null);
        bind = FragmentDetailArgumentsBinding.bind(view);
        initView();
        return view;
    }

    private void initView() {
        bind.llArgument.removeAllViews();
        ProductBean product = (ProductBean) getArguments().getSerializable("product");
        Map<String, Object> hashMap = new LinkedHashMap<>();
        hashMap.put("算力费", product.getDaypriceByPer());
        hashMap.put("托管费率", product.manageRate);
        hashMap.put("电价", product.lightPrice);
        hashMap.put("算力功耗", product.getPowerCount());
        hashMap.put("1天1T产出 来自鱼池", product.getDayProductOut());
        hashMap.put("当前币价 来源于火币", product.getCoinPrice());
        hashMap.put("上架时间", product.getStartDate());
        hashMap.put("产出到账时间", product.getProOutDate());
        hashMap.put("套餐期数", product.getPakeageDate());

        Iterator<Map.Entry<String, Object>> iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Object> entry = iterator.next();
            LayoutItemArgumentsBinding bind = LayoutItemArgumentsBinding.bind(LayoutInflater.from(getActivity())
                    .inflate(R.layout.layout_item_arguments, null));
            bind.tvName.setText(entry.getKey());
            bind.tvValue.setText(entry.getValue() + "");
            this.bind.llArgument.addView(bind.getRoot());
        }
    }

    public static DetailArgumentsFragment newInstance(ProductBean product) {
        Bundle args = new Bundle();
        DetailArgumentsFragment fragment = new DetailArgumentsFragment();
        args.putSerializable("product", product);
        fragment.setArguments(args);
        return fragment;
    }
}
